home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / g_quake / sprdgun2.zip / ITEMS.QC < prev    next >
Text File  |  1996-09-25  |  29KB  |  1,347 lines

  1. void() W_SetCurrentAmmo;
  2. /* ALL LIGHTS SHOULD BE 0 1 0 IN COLOR ALL OTHER ITEMS SHOULD
  3. BE .8 .3 .4 IN COLOR */
  4.  
  5.  
  6. void() SUB_regen =
  7. {
  8.     self.model = self.mdl;        // restore original model
  9.     self.solid = SOLID_TRIGGER;    // allow it to be touched again
  10.     sound (self, CHAN_VOICE, "items/itembk2.wav", 1, ATTN_NORM);    // play respawn sound
  11.     setorigin (self, self.origin);
  12. };
  13.  
  14.  
  15.  
  16. /*QUAKED noclass (0 0 0) (-8 -8 -8) (8 8 8)
  17. prints a warning message when spawned
  18. */
  19. void() noclass =
  20. {
  21.     dprint ("noclass spawned at");
  22.     dprint (vtos(self.origin));
  23.     dprint ("\n");
  24.     remove (self);
  25. };
  26.  
  27.  
  28.  
  29. /*
  30. ============
  31. PlaceItem
  32.  
  33. plants the object on the floor
  34. ============
  35. */
  36. void() PlaceItem =
  37. {
  38.     local float    oldz;
  39.  
  40.     self.mdl = self.model;        // so it can be restored on respawn
  41.     self.flags = FL_ITEM;        // make extra wide
  42.     self.solid = SOLID_TRIGGER;
  43.     self.movetype = MOVETYPE_TOSS;    
  44.     self.velocity = '0 0 0';
  45.     self.origin_z = self.origin_z + 6;
  46.     oldz = self.origin_z;
  47.     if (!droptofloor())
  48.     {
  49.         dprint ("Bonus item fell out of level at ");
  50.         dprint (vtos(self.origin));
  51.         dprint ("\n");
  52.         remove(self);
  53.         return;
  54.     }
  55. };
  56.  
  57. /*
  58. ============
  59. StartItem
  60.  
  61. Sets the clipping size and plants the object on the floor
  62. ============
  63. */
  64. void() StartItem =
  65. {
  66.     self.nextthink = time + 0.2;    // items start after other solids
  67.     self.think = PlaceItem;
  68. };
  69.  
  70. /*
  71. =========================================================================
  72.  
  73. HEALTH BOX
  74.  
  75. =========================================================================
  76. */
  77. //
  78. // T_Heal: add health to an entity, limiting health to max_health
  79. // "ignore" will ignore max_health limit
  80. //
  81. float (entity e, float healamount, float ignore) T_Heal =
  82. {
  83.     if (e.health <= 0)
  84.         return 0;
  85.     if ((!ignore) && (e.health >= other.max_health))
  86.         return 0;
  87.     healamount = ceil(healamount);
  88.  
  89.     e.health = e.health + healamount;
  90.     if ((!ignore) && (e.health >= other.max_health))
  91.         e.health = other.max_health;
  92.         
  93.     if (e.health > 250)
  94.         e.health = 250;
  95.     return 1;
  96. };
  97.  
  98. /*QUAKED item_health (.3 .3 1) (0 0 0) (32 32 32) rotten megahealth
  99. Health box. Normally gives 25 points.
  100. Rotten box heals 5-10 points,
  101. megahealth will add 100 health, then 
  102. rot you down to your maximum health limit, 
  103. one point per second.
  104. */
  105.  
  106. float    H_ROTTEN = 1;
  107. float    H_MEGA = 2;
  108. .float    healamount, healtype;
  109. void() health_touch;
  110. void() item_megahealth_rot;
  111.  
  112. void() item_health =
  113. {    
  114.     self.touch = health_touch;
  115.  
  116.     if (self.spawnflags & H_ROTTEN)
  117.     {
  118.         precache_model("maps/b_bh10.bsp");
  119.  
  120.         precache_sound("items/r_item1.wav");
  121.         setmodel(self, "maps/b_bh10.bsp");
  122.         self.noise = "items/r_item1.wav";
  123.         self.healamount = 15;
  124.         self.healtype = 0;
  125.     }
  126.     else
  127.     if (self.spawnflags & H_MEGA)
  128.     {
  129.         precache_model("maps/b_bh100.bsp");
  130.         precache_sound("items/r_item2.wav");
  131.         setmodel(self, "maps/b_bh100.bsp");
  132.         self.noise = "items/r_item2.wav";
  133.         self.healamount = 100;
  134.         self.healtype = 2;
  135.     }
  136.     else
  137.     {
  138.         precache_model("maps/b_bh25.bsp");
  139.         precache_sound("items/health1.wav");
  140.         setmodel(self, "maps/b_bh25.bsp");
  141.         self.noise = "items/health1.wav";
  142.         self.healamount = 25;
  143.         self.healtype = 1;
  144.     }
  145.     setsize (self, '0 0 0', '32 32 56');
  146.     StartItem ();
  147. };
  148.  
  149.  
  150. void() health_touch =
  151. {
  152.     local    float amount;
  153.     local    string    s;
  154.     
  155.     if (other.classname != "player")
  156.         return;
  157.     
  158.     if (self.healtype == 2) // Megahealth?  Ignore max_health...
  159.     {
  160.         if (other.health >= 250)
  161.             return;
  162.         if (!T_Heal(other, self.healamount, 1))
  163.             return;
  164.     }
  165.     else
  166.     {
  167.         if (!T_Heal(other, self.healamount, 0))
  168.             return;
  169.     }
  170.     
  171.     sprint(other, "You receive ");
  172.     s = ftos(self.healamount);
  173.     sprint(other, s);
  174.     sprint(other, " health\n");
  175.     
  176. // health touch sound
  177.     sound(other, CHAN_ITEM, self.noise, 1, ATTN_NORM);
  178.  
  179.     stuffcmd (other, "bf\n");
  180.     
  181.     self.model = string_null;
  182.     self.solid = SOLID_NOT;
  183.  
  184.     // Megahealth = rot down the player's super health
  185.     if (self.healtype == 2)
  186.     {
  187.         other.items = other.items | IT_SUPERHEALTH;
  188.         self.nextthink = time + 5;
  189.         self.think = item_megahealth_rot;
  190.         self.owner = other;
  191.     }
  192.     else
  193.     {
  194.         if (deathmatch != 2)        // deathmatch 2 is the silly old rules
  195.         {
  196.             if (deathmatch)
  197.                 self.nextthink = time + 20;
  198.             self.think = SUB_regen;
  199.         }
  200.     }
  201.     
  202.     activator = other;
  203.     SUB_UseTargets();                // fire all targets / killtargets
  204. };    
  205.  
  206. void() item_megahealth_rot =
  207. {
  208.     other = self.owner;
  209.     
  210.     if (other.health > other.max_health)
  211.     {
  212.         other.health = other.health - 1;
  213.         self.nextthink = time + 1;
  214.         return;
  215.     }
  216.  
  217. // it is possible for a player to die and respawn between rots, so don't
  218. // just blindly subtract the flag off
  219.     other.items = other.items - (other.items & IT_SUPERHEALTH);
  220.     
  221.     if (deathmatch == 1)    // deathmatch 2 is silly old rules
  222.     {
  223.         self.nextthink = time + 20;
  224.         self.think = SUB_regen;
  225.     }
  226. };
  227.  
  228. /*
  229. ===============================================================================
  230.  
  231. ARMOR
  232.  
  233. ===============================================================================
  234. */
  235.  
  236. void() armor_touch;
  237.  
  238. void() armor_touch =
  239. {
  240.     local    float    type, value, bit;
  241.     
  242.     if (other.health <= 0)
  243.         return;
  244.     if (other.classname != "player")
  245.         return;
  246.  
  247.     if (self.classname == "item_armor1")
  248.     {
  249.         type = 0.3;
  250.         value = 100;
  251.         bit = IT_ARMOR1;
  252.     }
  253.     if (self.classname == "item_armor2")
  254.     {
  255.         type = 0.6;
  256.         value = 150;
  257.         bit = IT_ARMOR2;
  258.     }
  259.     if (self.classname == "item_armorInv")
  260.     {
  261.         type = 0.8;
  262.         value = 200;
  263.         bit = IT_ARMOR3;
  264.     }
  265.     if (other.armortype*other.armorvalue >= type*value)
  266.         return;
  267.         
  268.     other.armortype = type;
  269.     other.armorvalue = value;
  270.     other.items = other.items - (other.items & (IT_ARMOR1 | IT_ARMOR2 | IT_ARMOR3)) + bit;
  271.  
  272.     self.solid = SOLID_NOT;
  273.     self.model = string_null;
  274.     if (deathmatch == 1)
  275.         self.nextthink = time + 20;
  276.     self.think = SUB_regen;
  277.  
  278.     sprint(other, "You got armor\n");
  279. // armor touch sound
  280.     sound(other, CHAN_ITEM, "items/armor1.wav", 1, ATTN_NORM);
  281.     stuffcmd (other, "bf\n");
  282.     
  283.     activator = other;
  284.     SUB_UseTargets();                // fire all targets / killtargets
  285. };
  286.  
  287.  
  288. /*QUAKED item_armor1 (0 .5 .8) (-16 -16 0) (16 16 32)
  289. */
  290.  
  291. void() item_armor1 =
  292. {
  293.     self.touch = armor_touch;
  294.     precache_model ("progs/armor.mdl");
  295.     setmodel (self, "progs/armor.mdl");
  296.     self.skin = 0;
  297.     setsize (self, '-16 -16 0', '16 16 56');
  298.     StartItem ();
  299. };
  300.  
  301. /*QUAKED item_armor2 (0 .5 .8) (-16 -16 0) (16 16 32)
  302. */
  303.  
  304. void() item_armor2 =
  305. {
  306.     self.touch = armor_touch;
  307.     precache_model ("progs/armor.mdl");
  308.     setmodel (self, "progs/armor.mdl");
  309.     self.skin = 1;
  310.     setsize (self, '-16 -16 0', '16 16 56');
  311.     StartItem ();
  312. };
  313.  
  314. /*QUAKED item_armorInv (0 .5 .8) (-16 -16 0) (16 16 32)
  315. */
  316.  
  317. void() item_armorInv =
  318. {
  319.     self.touch = armor_touch;
  320.     precache_model ("progs/armor.mdl");
  321.     setmodel (self, "progs/armor.mdl");
  322.     self.skin = 2;
  323.     setsize (self, '-16 -16 0', '16 16 56');
  324.     StartItem ();
  325. };
  326.  
  327. /*
  328. ===============================================================================
  329.  
  330. WEAPONS
  331.  
  332. ===============================================================================
  333. */
  334.  
  335. void() bound_other_ammo =
  336. {
  337.     if (other.ammo_shells > 100)
  338.         other.ammo_shells = 100;
  339.     if (other.ammo_nails > 200)
  340.         other.ammo_nails = 200;
  341.     if (other.ammo_rockets > 100)
  342.         other.ammo_rockets = 100;        
  343.     if (other.ammo_cells > 100)
  344.         other.ammo_cells = 100;        
  345. };
  346.  
  347.  
  348. float(float w) RankForWeapon =
  349. {
  350.     if (w == IT_LIGHTNING)
  351.         return 1;
  352.     if (w == IT_ROCKET_LAUNCHER)
  353.         return 2;
  354.     if (w == IT_SUPER_NAILGUN)
  355.         return 3;
  356.     if (w == IT_GRENADE_LAUNCHER)
  357.         return 4;
  358.     if (w == IT_SUPER_SHOTGUN)
  359.         return 5;
  360.     if (w == IT_NAILGUN)
  361.         return 6;
  362.     return 7;
  363. };
  364.  
  365. /*
  366. =============
  367. Deathmatch_Weapon
  368.  
  369. Deathmatch weapon change rules for picking up a weapon
  370.  
  371. .float        ammo_shells, ammo_nails, ammo_rockets, ammo_cells;
  372. =============
  373. */
  374. void(float old, float new) Deathmatch_Weapon =
  375. {
  376.     local float or, nr;
  377.  
  378. // change self.weapon if desired
  379.     or = RankForWeapon (self.weapon);
  380.     nr = RankForWeapon (new);
  381.     if ( nr < or )
  382.         self.weapon = new;
  383. };
  384.  
  385. /*
  386. =============
  387. weapon_touch
  388. =============
  389. */
  390. float() W_BestWeapon;
  391.  
  392. void() weapon_touch =
  393. {
  394.     local    float    hadammo, best, new, old;
  395.     local    entity    stemp;
  396.     local    float    leave;
  397.  
  398.     if (!(other.flags & FL_CLIENT))
  399.         return;
  400.  
  401. // if the player was using his best weapon, change up to the new one if better        
  402.     stemp = self;
  403.     self = other;
  404.     best = W_BestWeapon();
  405.     self = stemp;
  406.  
  407.     if (deathmatch == 2 || coop)
  408.         leave = 1;
  409.     else
  410.         leave = 0;
  411.     
  412.     if (self.classname == "weapon_nailgun")
  413.     {
  414.         if (leave && (other.items & IT_NAILGUN) )
  415.             return;
  416.         hadammo = other.ammo_nails;    
  417.         other.items = other.items | IT_SPREAD_NAILGUN;        
  418.         new = IT_NAILGUN;
  419.         other.ammo_nails = other.ammo_nails + 30;
  420.     }
  421.     else if (self.classname == "weapon_supernailgun")
  422.     {
  423.         if (leave && (other.items & IT_SUPER_NAILGUN) )
  424.             return;
  425.         hadammo = other.ammo_rockets;            
  426.         new = IT_SUPER_NAILGUN;
  427.         other.ammo_nails = other.ammo_nails + 30;
  428.     }
  429.     else if (self.classname == "weapon_supershotgun")
  430.     {
  431.         if (leave && (other.items & IT_SUPER_SHOTGUN) )
  432.             return;
  433.         hadammo = other.ammo_rockets;            
  434.         new = IT_SUPER_SHOTGUN;
  435.         other.ammo_shells = other.ammo_shells + 5;
  436.     }
  437.     else if (self.classname == "weapon_rocketlauncher")
  438.     {
  439.         if (leave && (other.items & IT_ROCKET_LAUNCHER) )
  440.             return;
  441.         hadammo = other.ammo_rockets;            
  442.         new = IT_ROCKET_LAUNCHER;
  443.         other.ammo_rockets = other.ammo_rockets + 5;
  444.     }
  445.     else if (self.classname == "weapon_grenadelauncher")
  446.     {
  447.         if (leave && (other.items & IT_GRENADE_LAUNCHER) )
  448.             return;
  449.         hadammo = other.ammo_rockets;            
  450.         new = IT_GRENADE_LAUNCHER;
  451.         other.ammo_rockets = other.ammo_rockets + 5;
  452.     }
  453.     else if (self.classname == "weapon_lightning")
  454.     {
  455.         if (leave && (other.items & IT_LIGHTNING) )
  456.             return;
  457.         hadammo = other.ammo_rockets;            
  458.         new = IT_LIGHTNING;
  459.         other.ammo_cells = other.ammo_cells + 15;
  460.     }
  461.     else
  462.         objerror ("weapon_touch: unknown classname");
  463.  
  464.     sprint (other, "You got the ");
  465.     sprint (other, self.netname);
  466.     sprint (other, "\n");
  467. // weapon touch sound
  468.     sound (other, CHAN_ITEM, "weapons/pkup.wav", 1, ATTN_NORM);
  469.     stuffcmd (other, "bf\n");
  470.  
  471.     bound_other_ammo ();
  472.  
  473. // change to the weapon
  474.     old = other.items;
  475.     other.items = other.items | new;
  476.     
  477.     stemp = self;
  478.     self = other;
  479.  
  480.     if (!deathmatch)
  481.         self.weapon = new;
  482.     else
  483.         Deathmatch_Weapon (old, new);
  484.  
  485.     W_SetCurrentAmmo();
  486.  
  487.     self = stemp;
  488.  
  489.     if (leave)
  490.         return;
  491.  
  492. // remove it in single player, or setup for respawning in deathmatch
  493.     self.model = string_null;
  494.     self.solid = SOLID_NOT;
  495.     if (deathmatch == 1)
  496.         self.nextthink = time + 30;
  497.     self.think = SUB_regen;
  498.     
  499.     activator = other;
  500.     SUB_UseTargets();                // fire all targets / killtargets
  501. };
  502.  
  503.  
  504. /*QUAKED weapon_supershotgun (0 .5 .8) (-16 -16 0) (16 16 32)
  505. */
  506.  
  507. void() weapon_supershotgun =
  508. {
  509.     precache_model ("progs/g_shot.mdl");
  510.     setmodel (self, "progs/g_shot.mdl");
  511.     self.weapon = IT_SUPER_SHOTGUN;
  512.     self.netname = "Double-barrelled Shotgun";
  513.     self.touch = weapon_touch;
  514.     setsize (self, '-16 -16 0', '16 16 56');
  515.     StartItem ();
  516. };
  517.  
  518. /*QUAKED weapon_nailgun (0 .5 .8) (-16 -16 0) (16 16 32)
  519. */
  520.  
  521. void() weapon_nailgun =
  522. {
  523.     precache_model ("progs/g_nail.mdl");
  524.     setmodel (self, "progs/g_nail.mdl");
  525.     self.weapon = IT_NAILGUN;
  526.     self.netname = "nailgun";
  527.     self.touch = weapon_touch;
  528.     setsize (self, '-16 -16 0', '16 16 56');
  529.     StartItem ();
  530. };
  531.  
  532. /*QUAKED weapon_supernailgun (0 .5 .8) (-16 -16 0) (16 16 32)
  533. */
  534.  
  535. void() weapon_supernailgun =
  536. {
  537.     precache_model ("progs/g_nail2.mdl");
  538.     setmodel (self, "progs/g_nail2.mdl");
  539.     self.weapon = IT_SUPER_NAILGUN;
  540.     self.netname = "Super Nailgun";
  541.     self.touch = weapon_touch;
  542.     setsize (self, '-16 -16 0', '16 16 56');
  543.     StartItem ();
  544. };
  545.  
  546. /*QUAKED weapon_grenadelauncher (0 .5 .8) (-16 -16 0) (16 16 32)
  547. */
  548.  
  549. void() weapon_grenadelauncher =
  550. {
  551.     precache_model ("progs/g_rock.mdl");
  552.     setmodel (self, "progs/g_rock.mdl");
  553.     self.weapon = 3;
  554.     self.netname = "Grenade Launcher";
  555.     self.touch = weapon_touch;
  556.     setsize (self, '-16 -16 0', '16 16 56');
  557.     StartItem ();
  558. };
  559.  
  560. /*QUAKED weapon_rocketlauncher (0 .5 .8) (-16 -16 0) (16 16 32)
  561. */
  562.  
  563. void() weapon_rocketlauncher =
  564. {
  565.     precache_model ("progs/g_rock2.mdl");
  566.     setmodel (self, "progs/g_rock2.mdl");
  567.     self.weapon = 3;
  568.     self.netname = "Rocket Launcher";
  569.     self.touch = weapon_touch;
  570.     setsize (self, '-16 -16 0', '16 16 56');
  571.     StartItem ();
  572. };
  573.  
  574.  
  575. /*QUAKED weapon_lightning (0 .5 .8) (-16 -16 0) (16 16 32)
  576. */
  577.  
  578. void() weapon_lightning =
  579. {
  580.     precache_model ("progs/g_light.mdl");
  581.     setmodel (self, "progs/g_light.mdl");
  582.     self.weapon = 3;
  583.     self.netname = "Thunderbolt";
  584.     self.touch = weapon_touch;
  585.     setsize (self, '-16 -16 0', '16 16 56');
  586.     StartItem ();
  587. };
  588.  
  589.  
  590. /*
  591. ===============================================================================
  592.  
  593. AMMO
  594.  
  595. ===============================================================================
  596. */
  597.  
  598. void() ammo_touch =
  599. {
  600. local entity    stemp;
  601. local float        best;
  602.  
  603.     if (other.classname != "player")
  604.         return;
  605.     if (other.health <= 0)
  606.         return;
  607.  
  608. // if the player was using his best weapon, change up to the new one if better        
  609.     stemp = self;
  610.     self = other;
  611.     best = W_BestWeapon();
  612.     self = stemp;
  613.  
  614.  
  615. // shotgun
  616.     if (self.weapon == 1)
  617.     {
  618.         if (other.ammo_shells >= 100)
  619.             return;
  620.         other.ammo_shells = other.ammo_shells + self.aflag;
  621.     }
  622.  
  623. // spikes
  624.     if (self.weapon == 2)
  625.     {
  626.         if (other.ammo_nails >= 200)
  627.             return;
  628.         other.ammo_nails = other.ammo_nails + self.aflag;
  629.     }
  630.  
  631. //    rockets
  632.     if (self.weapon == 3)
  633.     {
  634.         if (other.ammo_rockets >= 100)
  635.             return;
  636.         other.ammo_rockets = other.ammo_rockets + self.aflag;
  637.     }
  638.  
  639. //    cells
  640.     if (self.weapon == 4)
  641.     {
  642.         if (other.ammo_cells >= 200)
  643.             return;
  644.         other.ammo_cells = other.ammo_cells + self.aflag;
  645.     }
  646.  
  647.     bound_other_ammo ();
  648.     
  649.     sprint (other, "You got the ");
  650.     sprint (other, self.netname);
  651.     sprint (other, "\n");
  652. // ammo touch sound
  653.     sound (other, CHAN_ITEM, "weapons/lock4.wav", 1, ATTN_NORM);
  654.     stuffcmd (other, "bf\n");
  655.  
  656. // change to a better weapon if appropriate
  657.  
  658.     if ( other.weapon == best )
  659.     {
  660.         stemp = self;
  661.         self = other;
  662.         self.weapon = W_BestWeapon();
  663.         W_SetCurrentAmmo ();
  664.         self = stemp;
  665.     }
  666.  
  667. // if changed current ammo, update it
  668.     stemp = self;
  669.     self = other;
  670.     W_SetCurrentAmmo();
  671.     self = stemp;
  672.  
  673. // remove it in single player, or setup for respawning in deathmatch
  674.     self.model = string_null;
  675.     self.solid = SOLID_NOT;
  676.     if (deathmatch == 1)
  677.         self.nextthink = time + 30;
  678.     
  679.     self.think = SUB_regen;
  680.  
  681.     activator = other;
  682.     SUB_UseTargets();                // fire all targets / killtargets
  683. };
  684.  
  685.  
  686.  
  687.  
  688. float WEAPON_BIG2 = 1;
  689.  
  690. /*QUAKED item_shells (0 .5 .8) (0 0 0) (32 32 32) big
  691. */
  692.  
  693. void() item_shells =
  694. {
  695.     self.touch = ammo_touch;
  696.  
  697.     if (self.spawnflags & WEAPON_BIG2)
  698.     {
  699.         precache_model ("maps/b_shell1.bsp");
  700.         setmodel (self, "maps/b_shell1.bsp");
  701.         self.aflag = 40;
  702.     }
  703.     else
  704.     {
  705.         precache_model ("maps/b_shell0.bsp");
  706.         setmodel (self, "maps/b_shell0.bsp");
  707.         self.aflag = 20;
  708.     }
  709.     self.weapon = 1;
  710.     self.netname = "shells";
  711.     setsize (self, '0 0 0', '32 32 56');
  712.     StartItem ();
  713. };
  714.  
  715. /*QUAKED item_spikes (0 .5 .8) (0 0 0) (32 32 32) big
  716. */
  717.  
  718. void() item_spikes =
  719. {
  720.     self.touch = ammo_touch;
  721.  
  722.     if (self.spawnflags & WEAPON_BIG2)
  723.     {
  724.         precache_model ("maps/b_nail1.bsp");
  725.         setmodel (self, "maps/b_nail1.bsp");
  726.         self.aflag = 50;
  727.     }
  728.     else
  729.     {
  730.         precache_model ("maps/b_nail0.bsp");
  731.         setmodel (self, "maps/b_nail0.bsp");
  732.         self.aflag = 25;
  733.     }
  734.     self.weapon = 2;
  735.     self.netname = "nails";
  736.     setsize (self, '0 0 0', '32 32 56');
  737.     StartItem ();
  738. };
  739.  
  740. /*QUAKED item_rockets (0 .5 .8) (0 0 0) (32 32 32) big
  741. */
  742.  
  743. void() item_rockets =
  744. {
  745.     self.touch = ammo_touch;
  746.  
  747.     if (self.spawnflags & WEAPON_BIG2)
  748.     {
  749.         precache_model ("maps/b_rock1.bsp");
  750.         setmodel (self, "maps/b_rock1.bsp");
  751.         self.aflag = 10;
  752.     }
  753.     else
  754.     {
  755.         precache_model ("maps/b_rock0.bsp");
  756.         setmodel (self, "maps/b_rock0.bsp");
  757.         self.aflag = 5;
  758.     }
  759.     self.weapon = 3;
  760.     self.netname = "rockets";
  761.     setsize (self, '0 0 0', '32 32 56');
  762.     StartItem ();
  763. };
  764.  
  765.  
  766. /*QUAKED item_cells (0 .5 .8) (0 0 0) (32 32 32) big
  767. */
  768.  
  769. void() item_cells =
  770. {
  771.     self.touch = ammo_touch;
  772.  
  773.     if (self.spawnflags & WEAPON_BIG2)
  774.     {
  775.         precache_model ("maps/b_batt1.bsp");
  776.         setmodel (self, "maps/b_batt1.bsp");
  777.         self.aflag = 12;
  778.     }
  779.     else
  780.     {
  781.         precache_model ("maps/b_batt0.bsp");
  782.         setmodel (self, "maps/b_batt0.bsp");
  783.         self.aflag = 6;
  784.     }
  785.     self.weapon = 4;
  786.     self.netname = "cells";
  787.     setsize (self, '0 0 0', '32 32 56');
  788.     StartItem ();
  789. };
  790.  
  791.  
  792. /*QUAKED item_weapon (0 .5 .8) (0 0 0) (32 32 32) shotgun rocket spikes big
  793. DO NOT USE THIS!!!! IT WILL BE REMOVED!
  794. */
  795.  
  796. float WEAPON_SHOTGUN = 1;
  797. float WEAPON_ROCKET = 2;
  798. float WEAPON_SPIKES = 4;
  799. float WEAPON_BIG = 8;
  800. void() item_weapon =
  801. {
  802.     self.touch = ammo_touch;
  803.  
  804.     if (self.spawnflags & WEAPON_SHOTGUN)
  805.     {
  806.         if (self.spawnflags & WEAPON_BIG)
  807.         {
  808.             precache_model ("maps/b_shell1.bsp");
  809.             setmodel (self, "maps/b_shell1.bsp");
  810.             self.aflag = 40;
  811.         }
  812.         else
  813.         {
  814.             precache_model ("maps/b_shell0.bsp");
  815.             setmodel (self, "maps/b_shell0.bsp");
  816.             self.aflag = 20;
  817.         }
  818.         self.weapon = 1;
  819.         self.netname = "shells";
  820.     }
  821.  
  822.     if (self.spawnflags & WEAPON_SPIKES)
  823.     {
  824.         if (self.spawnflags & WEAPON_BIG)
  825.         {
  826.             precache_model ("maps/b_nail1.bsp");
  827.             setmodel (self, "maps/b_nail1.bsp");
  828.             self.aflag = 40;
  829.         }
  830.         else
  831.         {
  832.             precache_model ("maps/b_nail0.bsp");
  833.             setmodel (self, "maps/b_nail0.bsp");
  834.             self.aflag = 20;
  835.         }
  836.         self.weapon = 2;
  837.         self.netname = "spikes";
  838.     }
  839.  
  840.     if (self.spawnflags & WEAPON_ROCKET)
  841.     {
  842.         if (self.spawnflags & WEAPON_BIG)
  843.         {
  844.             precache_model ("maps/b_rock1.bsp");
  845.             setmodel (self, "maps/b_rock1.bsp");
  846.             self.aflag = 10;
  847.         }
  848.         else
  849.         {
  850.             precache_model ("maps/b_rock0.bsp");
  851.             setmodel (self, "maps/b_rock0.bsp");
  852.             self.aflag = 5;
  853.         }
  854.         self.weapon = 3;
  855.         self.netname = "rockets";
  856.     }
  857.     
  858.     setsize (self, '0 0 0', '32 32 56');
  859.     StartItem ();
  860. };
  861.  
  862.  
  863. /*
  864. ===============================================================================
  865.  
  866. KEYS
  867.  
  868. ===============================================================================
  869. */
  870.  
  871. void() key_touch =
  872. {
  873. local entity    stemp;
  874. local float        best;
  875.  
  876.     if (other.classname != "player")
  877.         return;
  878.     if (other.health <= 0)
  879.         return;
  880.     if (other.items & self.items)
  881.         return;
  882.  
  883.     sprint (other, "You got the ");
  884.     sprint (other, self.netname);
  885.     sprint (other,"\n");
  886.  
  887.     sound (other, CHAN_ITEM, self.noise, 1, ATTN_NORM);
  888.     stuffcmd (other, "bf\n");
  889.     other.items = other.items | self.items;
  890.  
  891.     if (!coop)
  892.     {    
  893.         self.solid = SOLID_NOT;
  894.         self.model = string_null;
  895.     }
  896.  
  897.     activator = other;
  898.     SUB_UseTargets();                // fire all targets / killtargets
  899. };
  900.  
  901.  
  902. void() key_setsounds =
  903. {
  904.     if (world.worldtype == 0)
  905.     {
  906.         precache_sound ("misc/medkey.wav");
  907.         self.noise = "misc/medkey.wav";
  908.     }
  909.     if (world.worldtype == 1)
  910.     {
  911.         precache_sound ("misc/runekey.wav");
  912.         self.noise = "misc/runekey.wav";
  913.     }
  914.     if (world.worldtype == 2)
  915.     {
  916.         precache_sound2 ("misc/basekey.wav");
  917.         self.noise = "misc/basekey.wav";
  918.     }
  919. };
  920.  
  921. /*QUAKED item_key1 (0 .5 .8) (-16 -16 -24) (16 16 32)
  922. SILVER key
  923. In order for keys to work
  924. you MUST set your maps
  925. worldtype to one of the
  926. following:
  927. 0: medieval
  928. 1: metal
  929. 2: base
  930. */
  931.  
  932. void() item_key1 =
  933. {
  934.     if (world.worldtype == 0)
  935.     {
  936.         precache_model ("progs/w_s_key.mdl");
  937.         setmodel (self, "progs/w_s_key.mdl");
  938.         self.netname = "silver key";
  939.     }
  940.     else if (world.worldtype == 1)
  941.     {
  942.         precache_model ("progs/m_s_key.mdl");
  943.         setmodel (self, "progs/m_s_key.mdl");
  944.         self.netname = "silver runekey";
  945.     }
  946.     else if (world.worldtype == 2)
  947.     {
  948.         precache_model2 ("progs/b_s_key.mdl");
  949.         setmodel (self, "progs/b_s_key.mdl");
  950.         self.netname = "silver keycard";
  951.     }
  952.     key_setsounds();
  953.     self.touch = key_touch;
  954.     self.items = IT_KEY1;
  955.     setsize (self, '-16 -16 -24', '16 16 32');
  956.     StartItem ();
  957. };
  958.  
  959. /*QUAKED item_key2 (0 .5 .8) (-16 -16 -24) (16 16 32)
  960. GOLD key
  961. In order for keys to work
  962. you MUST set your maps
  963. worldtype to one of the
  964. following:
  965. 0: medieval
  966. 1: metal
  967. 2: base
  968. */
  969.  
  970. void() item_key2 =
  971. {
  972.     if (world.worldtype == 0)
  973.     {
  974.         precache_model ("progs/w_g_key.mdl");
  975.         setmodel (self, "progs/w_g_key.mdl");
  976.         self.netname = "gold key";
  977.     }
  978.     if (world.worldtype == 1)
  979.     {
  980.         precache_model ("progs/m_g_key.mdl");
  981.         setmodel (self, "progs/m_g_key.mdl");
  982.         self.netname = "gold runekey";
  983.     }
  984.     if (world.worldtype == 2)
  985.     {
  986.         precache_model2 ("progs/b_g_key.mdl");
  987.         setmodel (self, "progs/b_g_key.mdl");
  988.         self.netname = "gold keycard";
  989.     }
  990.     key_setsounds();
  991.     self.touch = key_touch;
  992.     self.items = IT_KEY2;
  993.     setsize (self, '-16 -16 -24', '16 16 32');
  994.     StartItem ();
  995. };
  996.  
  997.  
  998.  
  999. /*
  1000. ===============================================================================
  1001.  
  1002. END OF LEVEL RUNES
  1003.  
  1004. ===============================================================================
  1005. */
  1006.  
  1007. void() sigil_touch =
  1008. {
  1009. local entity    stemp;
  1010. local float        best;
  1011.  
  1012.     if (other.classname != "player")
  1013.         return;
  1014.     if (other.health <= 0)
  1015.         return;
  1016.  
  1017.     centerprint (other, "You got the rune!");
  1018.  
  1019.     sound (other, CHAN_ITEM, self.noise, 1, ATTN_NORM);
  1020.     stuffcmd (other, "bf\n");
  1021.     self.solid = SOLID_NOT;
  1022.     self.model = string_null;
  1023.     serverflags = serverflags | (self.spawnflags & 15);
  1024.     self.classname = "";        // so rune doors won't find it
  1025.     
  1026.     activator = other;
  1027.     SUB_UseTargets();                // fire all targets / killtargets
  1028. };
  1029.  
  1030.  
  1031. /*QUAKED item_sigil (0 .5 .8) (-16 -16 -24) (16 16 32) E1 E2 E3 E4
  1032. End of level sigil, pick up to end episode and return to jrstart.
  1033. */
  1034.  
  1035. void() item_sigil =
  1036. {
  1037.     if (!self.spawnflags)
  1038.         objerror ("no spawnflags");
  1039.  
  1040.     precache_sound ("misc/runekey.wav");
  1041.     self.noise = "misc/runekey.wav";
  1042.  
  1043.     if (self.spawnflags & 1)
  1044.     {
  1045.         precache_model ("progs/end1.mdl");
  1046.         setmodel (self, "progs/end1.mdl");
  1047.     }
  1048.     if (self.spawnflags & 2)
  1049.     {
  1050.         precache_model2 ("progs/end2.mdl");
  1051.         setmodel (self, "progs/end2.mdl");
  1052.     }
  1053.     if (self.spawnflags & 4)
  1054.     {
  1055.         precache_model2 ("progs/end3.mdl");
  1056.         setmodel (self, "progs/end3.mdl");
  1057.     }
  1058.     if (self.spawnflags & 8)
  1059.     {
  1060.         precache_model2 ("progs/end4.mdl");
  1061.         setmodel (self, "progs/end4.mdl");
  1062.     }
  1063.     
  1064.     self.touch = sigil_touch;
  1065.     setsize (self, '-16 -16 -24', '16 16 32');
  1066.     StartItem ();
  1067. };
  1068.  
  1069. /*
  1070. ===============================================================================
  1071.  
  1072. POWERUPS
  1073.  
  1074. ===============================================================================
  1075. */
  1076.  
  1077. void() powerup_touch;
  1078.  
  1079.  
  1080. void() powerup_touch =
  1081. {
  1082. local entity    stemp;
  1083. local float        best;
  1084.  
  1085.     if (other.classname != "player")
  1086.         return;
  1087.     if (other.health <= 0)
  1088.         return;
  1089.  
  1090.     sprint (other, "You got the ");
  1091.     sprint (other, self.netname);
  1092.     sprint (other,"\n");
  1093.  
  1094.     if (deathmatch)
  1095.     {
  1096.         self.mdl = self.model;
  1097.         
  1098.         if ((self.classname == "item_artifact_invulnerability") ||
  1099.             (self.classname == "item_artifact_invisibility"))
  1100.             self.nextthink = time + 60*5;
  1101.         else
  1102.             self.nextthink = time + 60;
  1103.         
  1104.         self.think = SUB_regen;
  1105.     }    
  1106.  
  1107.     sound (other, CHAN_VOICE, self.noise, 1, ATTN_NORM);
  1108.     stuffcmd (other, "bf\n");
  1109.     self.solid = SOLID_NOT;
  1110.     other.items = other.items | self.items;
  1111.     self.model = string_null;
  1112.  
  1113. // do the apropriate action
  1114.     if (self.classname == "item_artifact_envirosuit")
  1115.     {
  1116.         other.rad_time = 1;
  1117.         other.radsuit_finished = time + 30;
  1118.     }
  1119.     
  1120.     if (self.classname == "item_artifact_invulnerability")
  1121.     {
  1122.         other.invincible_time = 1;
  1123.         other.invincible_finished = time + 30;
  1124.     }
  1125.     
  1126.     if (self.classname == "item_artifact_invisibility")
  1127.     {
  1128.         other.invisible_time = 1;
  1129.         other.invisible_finished = time + 30;
  1130.     }
  1131.  
  1132.     if (self.classname == "item_artifact_super_damage")
  1133.     {
  1134.         other.super_time = 1;
  1135.         other.super_damage_finished = time + 30;
  1136.     }    
  1137.  
  1138.     activator = other;
  1139.     SUB_UseTargets();                // fire all targets / killtargets
  1140. };
  1141.  
  1142.  
  1143.  
  1144. /*QUAKED item_artifact_invulnerability (0 .5 .8) (-16 -16 -24) (16 16 32)
  1145. Player is invulnerable for 30 seconds
  1146. */
  1147. void() item_artifact_invulnerability =
  1148. {
  1149.     self.touch = powerup_touch;
  1150.  
  1151.     precache_model ("progs/invulner.mdl");
  1152.     precache_sound ("items/protect.wav");
  1153.     precache_sound ("items/protect2.wav");
  1154.     precache_sound ("items/protect3.wav");
  1155.     self.noise = "items/protect.wav";
  1156.     setmodel (self, "progs/invulner.mdl");
  1157.     self.netname = "Pentagram of Protection";
  1158.     self.items = IT_INVULNERABILITY;
  1159.     setsize (self, '-16 -16 -24', '16 16 32');
  1160.     StartItem ();
  1161. };
  1162.  
  1163. /*QUAKED item_artifact_envirosuit (0 .5 .8) (-16 -16 -24) (16 16 32)
  1164. Player takes no damage from water or slime for 30 seconds
  1165. */
  1166. void() item_artifact_envirosuit =
  1167. {
  1168.     self.touch = powerup_touch;
  1169.  
  1170.     precache_model ("progs/suit.mdl");
  1171.     precache_sound ("items/suit.wav");
  1172.     precache_sound ("items/suit2.wav");
  1173.     self.noise = "items/suit.wav";
  1174.     setmodel (self, "progs/suit.mdl");
  1175.     self.netname = "Biosuit";
  1176.     self.items = IT_SUIT;
  1177.     setsize (self, '-16 -16 -24', '16 16 32');
  1178.     StartItem ();
  1179. };
  1180.  
  1181.  
  1182. /*QUAKED item_artifact_invisibility (0 .5 .8) (-16 -16 -24) (16 16 32)
  1183. Player is invisible for 30 seconds
  1184. */
  1185. void() item_artifact_invisibility =
  1186. {
  1187.     self.touch = powerup_touch;
  1188.  
  1189.     precache_model ("progs/invisibl.mdl");
  1190.     precache_sound ("items/inv1.wav");
  1191.     precache_sound ("items/inv2.wav");
  1192.     precache_sound ("items/inv3.wav");
  1193.     self.noise = "items/inv1.wav";
  1194.     setmodel (self, "progs/invisibl.mdl");
  1195.     self.netname = "Ring of Shadows";
  1196.     self.items = IT_INVISIBILITY;
  1197.     setsize (self, '-16 -16 -24', '16 16 32');
  1198.     StartItem ();
  1199. };
  1200.  
  1201.  
  1202. /*QUAKED item_artifact_super_damage (0 .5 .8) (-16 -16 -24) (16 16 32)
  1203. The next attack from the player will do 4x damage
  1204. */
  1205. void() item_artifact_super_damage =
  1206. {
  1207.     self.touch = powerup_touch;
  1208.  
  1209.     precache_model ("progs/quaddama.mdl");
  1210.     precache_sound ("items/damage.wav");
  1211.     precache_sound ("items/damage2.wav");
  1212.     precache_sound ("items/damage3.wav");
  1213.     self.noise = "items/damage.wav";
  1214.     setmodel (self, "progs/quaddama.mdl");
  1215.     self.netname = "Quad Damage";
  1216.     self.items = IT_QUAD;
  1217.     setsize (self, '-16 -16 -24', '16 16 32');
  1218.     StartItem ();
  1219. };
  1220.  
  1221.  
  1222.  
  1223. /*
  1224. ===============================================================================
  1225.  
  1226. PLAYER BACKPACKS
  1227.  
  1228. ===============================================================================
  1229. */
  1230.  
  1231. void() BackpackTouch =
  1232. {
  1233.     local string    s;
  1234.     local    float    best;
  1235.     local        entity    stemp;
  1236.     
  1237.     if (other.classname != "player")
  1238.         return;
  1239.     if (other.health <= 0)
  1240.         return;
  1241.         
  1242. // if the player was using his best weapon, change up to the new one if better        
  1243.     stemp = self;
  1244.     self = other;
  1245.     best = W_BestWeapon();
  1246.     self = stemp;
  1247.  
  1248. // change weapons
  1249.     other.ammo_shells = other.ammo_shells + self.ammo_shells;
  1250.     other.ammo_nails = other.ammo_nails + self.ammo_nails;
  1251.     other.ammo_rockets = other.ammo_rockets + self.ammo_rockets;
  1252.     other.ammo_cells = other.ammo_cells + self.ammo_cells;
  1253.  
  1254.     other.items = other.items | self.items;
  1255.     
  1256.     bound_other_ammo ();
  1257.  
  1258.     sprint (other, "You get ");
  1259.  
  1260.     if (self.ammo_shells)
  1261.     {
  1262.         s = ftos(self.ammo_shells);
  1263.         sprint (other, s);
  1264.         sprint (other, " shells  ");
  1265.     }
  1266.     if (self.ammo_nails)
  1267.     {
  1268.         s = ftos(self.ammo_nails);
  1269.         sprint (other, s);
  1270.         sprint (other, " nails ");
  1271.     }
  1272.     if (self.ammo_rockets)
  1273.     {
  1274.         s = ftos(self.ammo_rockets);
  1275.         sprint (other, s);
  1276.         sprint (other, " rockets  ");
  1277.     }
  1278.     if (self.ammo_cells)
  1279.     {
  1280.         s = ftos(self.ammo_cells);
  1281.         sprint (other, s);
  1282.         sprint (other, " cells  ");
  1283.     }
  1284.     
  1285.     sprint (other, "\n");
  1286. // backpack touch sound
  1287.     sound (other, CHAN_ITEM, "weapons/lock4.wav", 1, ATTN_NORM);
  1288.     stuffcmd (other, "bf\n");
  1289.  
  1290. // change to a better weapon if appropriate
  1291.     if ( other.weapon == best )
  1292.     {
  1293.         stemp = self;
  1294.         self = other;
  1295.         self.weapon = W_BestWeapon();
  1296.         self = stemp;
  1297.     }
  1298.  
  1299.     
  1300.     remove(self);
  1301.     
  1302.     self = other;
  1303.     W_SetCurrentAmmo ();
  1304. };
  1305.  
  1306. /*
  1307. ===============
  1308. DropBackpack
  1309. ===============
  1310. */
  1311. void() DropBackpack =
  1312. {
  1313.     local entity    item;
  1314.  
  1315.     if (!(self.ammo_shells + self.ammo_nails + self.ammo_rockets + self.ammo_cells))
  1316.         return;    // nothing in it
  1317.  
  1318.     item = spawn();
  1319.     item.origin = self.origin - '0 0 24';
  1320.  
  1321.     // if weapon is spread nailgun, change quickly to nailgun
  1322.         if (self.weapon == IT_SPREAD_NAILGUN)
  1323.                 self.weapon = IT_NAILGUN;
  1324.  
  1325.     
  1326.     item.items = self.weapon;
  1327.  
  1328.     item.ammo_shells = self.ammo_shells;
  1329.     item.ammo_nails = self.ammo_nails;
  1330.     item.ammo_rockets = self.ammo_rockets;
  1331.     item.ammo_cells = self.ammo_cells;
  1332.  
  1333.     item.velocity_z = 300;
  1334.     item.velocity_x = -100 + (random() * 200);
  1335.     item.velocity_y = -100 + (random() * 200);
  1336.     
  1337.     item.flags = FL_ITEM;
  1338.     item.solid = SOLID_TRIGGER;
  1339.     item.movetype = MOVETYPE_TOSS;
  1340.     setmodel (item, "progs/backpack.mdl");
  1341.     setsize (item, '-16 -16 0', '16 16 56');
  1342.     item.touch = BackpackTouch;
  1343.     
  1344.     item.nextthink = time + 120;    // remove after 2 minutes
  1345.     item.think = SUB_Remove;
  1346. };
  1347.